const express = require('express');
const axios = require('axios');
const router = express.Router();

//bilibili直播接口
router.all('/bili-zhibo', async (req, res) => {
    try {
        if(req.method.toUpperCase() !== 'POST'){
            return res.json({
                msg: '请求方法必须为 POST',
                code: '001',
                data: []
            })
        }
        //页码
        let page = req.body.page ? req.body.page : 1;
        let areaId = req.body.areaId ? req.body.areaId : 0;
        console.log(areaId);

        let { data } = await axios.get(`https://api.live.bilibili.com/room/v1/Area/getListByAreaID?areaId=${areaId}&sort=dynamic&page=${page}&pageSize=12`);
        res.send({
            msg: '请求成功',
            code: '000',
            data: data
        })
    } catch (e) {
        console.log(e);
        res.json({
            msg: '请求错误',
            code: '004'
        })
    }
})

module.exports = router;